<?php
namespace app\base\model;
use think\Model;
/**
 * Created by PhpStorm.
 * User: Mikkle
 * Q Q:776329498
 * Date: 2017/2/8
 * Time: 1:01
 */
class AdminUser extends  Model
{
    protected $table = "my_admin_user";
    protected $name = "adminUser";


//    public function getInfoByOpenid($open_id){
//        return $this->where('weixin_openid',$open_id)->find();
//    }
//
//    //方法一
//    public function getDepartmentIdAttr($value,$data)
//    {
//        return $this->belongsTo('AdminDepartment','department_id','id')->where('id',$value)->value('name');
//    }

//    //方法二
//    public function getDepartmentIdAttr($value,$data)
//    {
//        return $this->belongsTo('AdminDepartment','department_id','id')->where('id',$data['department_id'])->value('name');
//    }


    public function getInfoByOpenid($open_id){
        return $this->where('weixin_openid',$open_id)->cache($this->table.'_'.$open_id,600)->find()->toArray();
    }

    public function getDepartmentIdAttr($value,$data)
    {
        return $this->belongsTo('AdminDepartment')->where('id',$value)->value('name');
    }
    public function getRoleIdAttr($value,$data){
        //$ids = $this->belongsTo('AdminRole')->where('id',$value)->value('rule') ;
        return $ids = $this->belongsTo('AdminNode')->where('id','in',$this->belongsTo('AdminRole')->where('id',$value)->value('rule'))->cache('AdminNode_'.$value)->select();
    }
}